// index.js
// 获取应用实例
const app = getApp()
const { httpPost, httpGet } = require('../common/js/http')
const  {formatTime}  = require("../../utils/util")

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    tabbar: {},
    statusBarHeight: 0,
    titHeight: '30px',
    indexBannerList: [],
    examVoList: [],
    articleList: [],
    vertical: false,
    autoplay: false,
    circular: false,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
    swiperCurrent: 0
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  onShow: function () {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        currentTab: 0  //数字是当前页面在tabbar的索引
      })
    }
    this.onLoad()
  },

  onLoad() {
    let that = this
    app.editTabbar();
    let menuButtonObject = wx.getMenuButtonBoundingClientRect()
    wx.getSystemInfo({
      success(res){
        that.setData({
          // statusBarHeight: res.statusBarHeight + 'px'
          statusBarHeight: menuButtonObject.top  + 'px',
          titHeight: menuButtonObject.height + 'px'
        })
        // console.log(res.statusBarHeight,menuButtonObject)
      }
    })
    httpGet({
      url: "/app/index/ordinary/getAppIndexVo",
      data: {},
      isLoding: true,
      lodingMsg: '加载中...'
    }).then(res => {

      if(res.errorCode == '0'){
        this.setData({
          indexBannerList: res.data.indexBannerList,
          examVoList: res.data.examVoList,
          articleList: res.data.articleList
        })
      }else{
        wx.showToast({
          icon: 'none',
          duration: 3000,
          title: res.message
        })
      }
      wx.stopPullDownRefresh()
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '海星职涯·测评云 ', // 子页面的title
      path: 'pages/index/index',
      // imageUrl: '/images/icon/logo.png'
      imageUrl: ''
    };
  },
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.onLoad()
  },
  // getUserInfo(e) {
  //   app.globalData.userInfo = e.detail.userInfo
  //   this.setData({
  //     userInfo: e.detail.userInfo,
  //     hasUserInfo: true
  //   })
  // },
  // getOpenid(){
  //   app.getOpenid().then(res => {
  //     console.log(res)
  //   })
  //   .catch(err => {
  //     console.log(err)
  //   })
  // },
  
  // changeProperty: function (e) {
  //   var propertyName = e.currentTarget.dataset.propertyName
  //   var newData = {}
  //   newData[propertyName] = e.detail.value
  //   this.setData(newData)
  // },
  // changeIndicatorDots: function (e) {
  //   this.setData({
  //     indicatorDots: !this.data.indicatorDots
  //   })
  // },
  // changeAutoplay: function (e) {
  //   this.setData({
  //     autoplay: !this.data.autoplay
  //   })
  // },
  // intervalChange: function (e) {
  //   this.setData({
  //     interval: e.detail.value
  //   })
  // },
  // durationChange: function (e) {
  //   this.setData({
  //     duration: e.detail.value
  //   })
  // },
  swiperChange: function(e) {
    this.setData({
      index: e.detail.current,
      swiperCurrent: e.detail.current
    })
  },

})
